Implementing a list with unique_ptr<>? [migrated]
Posted
by
Alexander Duchene
on Programmers
See other posts from Programmers
or by Alexander Duchene
Published on 2012-12-04T18:57:52Z
Indexed on
2012/12/05
5:30 UTC
Read the original article
Hit count: 202
As I understand it, a unique_ptr
signifies exclusive ownership. A singly linked list seems to fit this, with each node owning the next, like (pseduocode alert)
class node{
public:
unique_ptr<node> next;
int value;
};
but I don't understand how to perform operations like traversing the list, where I'm used to doing
here=here->next;
How do you implement data structures using unique_ptr
's? Are they the right tool for the job?
© Programmers or respective owner